import itertools

def get_largest_prime(n):
    if not (1000 <= n <= 9999):
        return 0
    digits = [int(d) for d in str(n)]
    combinations = []
    for i in range(1, len(digits) + 1):
        for combination in itertools.combinations(digits, i):
            num = int("".join(map(str, combination)))
            if num > 1:
                combinations.append(num)
    max_prime = 0
    for combination in combinations:
        if is_prime(combination) and combination > max_prime:
            max_prime = combination
    return max_prime


def is_prime(n):
    if n <= 1:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True


n = int(input())
result = get_largest_prime(n)
if result == 0:
    print(0)
else:
    print(result)
